package com.kaigejava.controller;

/**
 * Created by kaigejava on 2019/7/22.
 */

import com.kaigejava.domain.Salary;
import com.kaigejava.dto.LineDto;
import com.kaigejava.dto.Series;
import com.kaigejava.service.ISalaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@RequestMapping("salary")
@Controller
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;
    /**
     * 根据日期查询
     * @param start 开始时间
     * @param end   结束时间
     * @return
     */
    @RequestMapping("/getSalaryByDate")
    @ResponseBody
    public Map<String,Object> getSalaryByDate(String start,String end) throws ParseException {
        Map<String,Object> map = new HashMap<>();
        map.put("code",200);
        map.put("message","success");
        if(StringUtils.isBlank(start)
                || StringUtils.isBlank(end)){
            map.put("code",-200);
            map.put("message","开始时间或结束时间不能为空");
            return map;
        }

        List<Salary> list = salaryService.getSalaryByDate(start,end);
        List<String> ascissaData = new ArrayList<>();
        List<Series> Series = new ArrayList<>();
        com.kaigejava.dto.Series s1 = new Series();
        com.kaigejava.dto.Series s2 = new Series();
        List<Float> s1Data = new ArrayList<>();
        List<Float> s2Data = new ArrayList<>();
        for(Salary salary:list){
            ascissaData.add(salary.getSalaryDate().substring(5,salary.getSalaryDate().length()));
            s1Data.add(salary.getSalaryMoney());
            s2Data.add(salary.getCommission());
        }
        LineDto dto = new LineDto();
        s1.setData(s1Data);
        s1.setName("预计佣金");
        s1.setSmooth(false);
        s1.setType("line");
        s2.setData(s2Data);
        s2.setName("有效成交额");
        s2.setSmooth(false);
        s2.setType("line");
        Series.add(s1);
        Series.add(s2);
        dto.setSeries(Series);
        dto.setAscissaData(ascissaData);
        map.put("data",dto);
        return  map;
    }
}

